<?php

$userid = get_loggedin_userid();
$password = get_input('password');

if(strlen($password) < 6) {
    die(json_encode(export_result(400, "Password length is too short.")));
}

greengar_opinions_change_password($userid, $password);

$result = export_result(200, 'Your password has been changed');
echo json_encode($result);

function greengar_opinions_change_password($userid, $password) {
    
    $user = get_user($userid);

    $salt = genRandomString(8);
    $user->salt = $salt; // Reset the salt
    $user->password = generate_user_password($user, $password);
    $user->setMetaData('isWPUser', 0);
    $user->save();
    
}

?>
